﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LingDong.DataProvider;
using LingDong.KeywordExtract;
using LingDong.IndexReader;
using NLog;
using LingDong.IndexEntities.Document;
using System.IO;

namespace KeywordExtractExample
{
    class Program
    {
        static void Main(string[] args)
        {
            logger = LogManager.GetCurrentClassLogger();
            RunIndex();
        }

        private static void RunIndex()
        {
            using (Index index = new Index())
            using (StreamWriter sw = new StreamWriter(outputFile))
            {
                int maxdid = index.GetTotalDocumentCount();
                for (int i = 0; i < maxdid; i++)
                {
                    List<string> keywords = KeywordExtracter.GetHTMLKeywords(i, index);

                    OriginalDocumentEnity doc = index.GetOriginalDocument(i);
                    sw.WriteLine(doc.URL);
                    keywords.ForEach(k => sw.Write(k + "\t"));
                    sw.WriteLine();
                }
            }
        }

        private static void RunSingleHTML()
        {
            using (IDataReader dataReader = DataReaderFactory.CreateDataReader())
            using (Index index = new Index())
            {
                while (!dataReader.IsAllDataRead())
                {
                    DataEntity data = dataReader.GetNextData();
                    List<string> keywords = KeywordExtracter.GetHTMLKeywords(data.Content, index);

                    logger.Trace(data.Url);
                    keywords.ForEach(k => logger.Trace(k));
                }
            }
        }

        private static Logger logger;
        private static string outputFile = @"F:\LingDongData\Keyword\Result\output.txt";
    }
}
